<template>
  <div class="warning_dialog">
    <el-dialog
      :title="title"
      :visible.sync="dialogFlag"
      class="avue-dialog avue-dialog--top"
      width="60%"
      @close="cancel">
      <div style="margin: 10px 0">
        <el-form  :rules="rules" ref="ruleForm" :model="dataForm" label-width="100px" class="product-form">
          <el-row>
            <el-col :span="8">
              <el-form-item label="规则名称:" prop="pointCode">
                <el-input v-model="dataForm.pointCode" size="small" placeholder="请输入点位编码"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <div style="display: flex; justify-content: space-between; font-size: 16px; padding-bottom: 5px">
            <div>
              <span class="el-icon-tickets" style="margin-right: 15px"></span>
              <span>告警配置</span>
            </div>
          </div>
          <el-row>
            <el-col :span="8">
              <el-form-item label="规则名称:" prop="pointCode">
                <el-input v-model="dataForm.pointCode" size="small" placeholder="请输入点位编码"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div style="float: right">
        <el-button size="small" @click="cancel">取 消</el-button>
        <el-button size="small" type="primary" @click="determine">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import {save} from "@/api/warning/warningRule-api";

export default {
  name: "add",
  data() {
    return {
      title: '告警规则',
      dialogFlag: false,
      dataForm: {},
      // 判断写指令是否必填
      isWrite: true,
      rwDict: [],
      readDict: [],
      writeDict: [],
      dataTypeDict: [],
      rules: {
        pointCode: [
          {
            required: true,
            message: "请输入点位编码",
            trigger: 'blur'
          },
        ],
        pointName: [
          {
            required: true,
            message: "请输入点位名称",
            trigger: 'blur'
          }
        ],
        unit: [
          {
            required: true,
            message: "请输入单位",
            trigger: 'blur'
          }
        ],
        formula: [
          {
            required: true,
            message: "请输入转换公式",
            trigger: 'blur'
          }
        ],
        dataType: [
          {
            required: true,
            message: "请选择数据类型",
            trigger: 'blur'
          }
        ],
      },
    }
  },
  mounted() {

  },
  methods: {
    determine () {
      var dataForm = {}
      var data = {}
      var actions = []
      var log = {}
      data.id = "测试规则"
      data.sql = "SELECT * FROM chen"
      actions.push(log)
      data.actions = actions
      dataForm.ruleCondition = JSON.stringify(data)
      dataForm.ruleName = "测试规则"

      save(dataForm).then(res => {
      })
    },
    cancel () {
      this.dialogFlag = false;
      this.dataForm = {};
      this.$refs['ruleForm'].clearValidate();
      this.$emit('restOnLoad');
    },
    openDialog() {
      this.dialogFlag = true
    },
  }
}
</script>

<style scoped>
.product-form ::v-deep .el-form-item__label {
  color: #3f4448;
  font-weight: 400;
}

.warning_dialog ::v-deep .el-dialog__body {
  padding: 10px 20px;
}
</style>
